package com.lqian.threadpool;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * 四种线程池
 * @author: Melody_LQ
 * @time: 2022/7/14 10:29 上午
 */
public class ThreadPoolDemo implements Runnable{
    public static void main(String[] args) {
        ExecutorService pool = Executors.newFixedThreadPool(3);
        //ExecutorService pool = Executors.newSingleThreadExecutor();
        //ExecutorService pool = Executors.newCachedThreadPool();
        long start = System.currentTimeMillis();
        for (int i = 0; i <= 100 ; i++) {
            pool.execute(new ThreadPoolDemo());
        }
        long end = System.currentTimeMillis();
        System.out.println("expand：" + (end - start));
    }
    @Override
    public void run() {
        try {
            Thread.sleep(10);
            System.out.println("--->"+Thread.currentThread().getName()+"挑了一堆土");
            /**
             *
             --->pool-1-thread-2
             --->pool-1-thread-3
             --->pool-1-thread-1
             */
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
